﻿using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure.Interception;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.SQLite;
using System.IO;
using Models.SqlitModel;

namespace DbHelper
{
    public class SqliteContext : DbContext
    {
        public SqliteContext() : base(new SQLiteConnection()
        {
            ConnectionString = new SQLiteConnectionStringBuilder()
            {
                DataSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\BookDB.db"),
                ForeignKeys = true
            }.ConnectionString
        }, true)
        {
            DbInterception.Add(new SqliteInterceptor());

        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            base.OnModelCreating(modelBuilder);
        }


        public DbSet<Books> Books { get; set; }
        public DbSet<BooksChapter> BooksChapter { get; set; }
    }
}
